<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../plugins/layui/css/myPage.css">

</head>
<body>
<div class="layui-container">


    <form class="layui-form">
        <div class="layui-row">
            <div class="layui-col-md12">

                <fieldset class="layui-elem-field" style="margin-top: 20px;">
                    <legend>修改密码</legend>


                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"style="width: 100px;"><span style="color: red;">*</span>您的旧密码</label>
                            <div class="layui-input-inline" style="width: 170px;">
                                <input   type="password" name="oldpsw" lay-verify="required" required   class="layui-input" id="oldpsw" >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"style="width: 100px;"><span style="color: red;">*</span>您的新密码</label>
                            <div class="layui-input-inline" style="width: 170px;">
                                <input   type="password" name="mima" lay-verify="required" required   class="layui-input" id="mima" placeholder="长度6-12位的数字或字母">
                                <input   type="hidden" name="yhid"    id="yhid" >
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 100px;"><span style="color: red;">*</span>确认密码</label>
                            <div class="layui-input-inline" style="width: 170px;">
                                <input   type="password"   lay-verify="required|qrmima" required  placeholder="长度6-12位的数字或字母" class="layui-input" id="qrxmm" lay-filter = "qrxmm">
                            </div>
                        </div>
                    </div>
                </fieldset>
            </div>
        </div>

        <button id="modiSub" class="layui-btn layui-btn-normal "  lay-submit lay-filter="update" style="width: 10%; position: absolute;left: 35%"  >立即提交</button>

    </form>
</div>
<script src="../plugins/layui/layui.js"></script>
<script src="../js/config.js"></script>
<script src="../js/tools.js"></script>
<script type="text/javascript">
    layui.use(['table','form','layer','laydate','upload'],function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.$;
        var layer = layui.layer;
        var laydate = layui.laydate;
           var $ = layui.jquery;


        $.ajax({
            url: contextPath+"/currentUser",
            type: "GET",
            contentType:"application/json;charset=utf-8",
            dataType:"json",
            success: function(res) {
                currentUser = res.yhid;
                console.log(res);
                $("#yhid").val(currentUser);
            }
        });
        form.verify({
            qrmima: function(value,item){ //value：表单的值、item：表单的DOM对象
                var mima = $("#mima").val();
                if (mima != value) {
                    return '两次密码输入不同';

                }
            }


        });

            form.on('submit(update)', function(data){
            console.log(data.field);

            $("input").css("border","");
            $.ajax({
                url: contextPath+"/mima",
                type: "PUT",
                contentType:"application/json;charset=utf-8",
                data: JSON.stringify(data.field) ,
                dataType:"json",
                success: function(res) {

                    layer.msg(res.message,{
                        icon: 1,
                        time: 1000 //2秒关闭（如果不配置，默认是3秒）
                    } );
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });

   </script>
</form>
</body>
</html>